package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.model.vo.IndexCategoryVo;
import com.atguigu.gmall.product.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 对接后台管理系统:/admin/product相关请求
 * @author dyqstart
 * @create 2021-07-31-21:45
 * @since 1.0.0
 */
@Api(tags = "商品基础属性接口")
@RequestMapping("/admin/product")
@RestController
@Slf4j
public class ProductAdminController {

    @Autowired
    private CategoryService categoryService;


    @GetMapping("/getAllCategorys")
    public List<IndexCategoryVo> getAllCategorysForIndexHtml(){

        return categoryService.getAllCategorysForIndexHtml();
    }



    @ApiOperation("查询所有的一级分类信息")
    @GetMapping("getCategory1")
    public Result<List<BaseCategory1>> getCategory1(){

        List<BaseCategory1> category1s = categoryService.getCategory1();

        return Result.ok(category1s);
    }

    @ApiOperation("查询所有的二级分类信息")
    @GetMapping("getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(
            @ApiParam(value = "id",required = true)
            @PathVariable("category1Id") Long category1Id){

        if (category1Id > 0){
            List<BaseCategory2> category2s = categoryService.getCategory2(category1Id);
            return Result.ok(category2s);
        } else {
            return Result.build(null, ResultCodeEnum.SECKILL_ILLEGAL);
        }
    }

    @ApiOperation("查询所有的三级分类信息")
    @GetMapping("getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory3(
            @ApiParam(value = "id",required = true)
            @PathVariable("category2Id") Long category2Id){

        if (category2Id > 0){
            List<BaseCategory3> category3s = categoryService.getCategory3(category2Id);
            return Result.ok(category3s);
        } else {
            return Result.build(null,ResultCodeEnum.SECKILL_ILLEGAL);
        }

    }
}
